<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="Pragma" content="no-cache">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<title>会议室日程</title>
		<link rel="stylesheet" type="text/css" href="${base}/css/date.css" />
		<link rel="stylesheet" type="text/css" href="${base}/css/weui.min.css" />
		<script type="text/javascript">
			function stops() {
				return false;
			}
			document.oncontextmenu = stops;
		</script>
		<%
		    String userid=(String)request.getAttribute("loginuser");		   
		%>
		<style type="text/css">
			html,
			body,
			.page {
				height: 100%
			}
			
			.weui-panel:before,
			.weui-panel:after {
				border: 0px;
			}
			
			#details:after {
				content: "";
				clear: both;
				display: table
			}
			
			.weui-flex__item {
				margin: 5px;
			}
			
			.weui-mask,
			.weui-dialog {
				opacity: 1;
				visibility: visible;
			}
			
			.weui-dialog__bd {
				line-height: 40px
			}
		</style>
	</head>

	<body>

		<div class="page" id="container">
			<div class="weui-tab">
				<div class="weui-tab__bd">
					<div class="wrapper02" id="demo06">
						<div class="scroller">
							<ul class="clearfix">

							</ul>
						</div>
					</div>
					<div id="details">
						<div class="left">
							<div class="room" style="margin-bottom:5px;border-right:none;color: #000;cursor: pointer;">
								<div>会议室名称</div>
							</div>
							<ul>
								<li>上午<br />(9:00~12:00)</li>
								<li>下午<br />(14:00~18:00)</li>
							</ul>
						</div>
						<div class="right">
							<div class="room">
								<div style="color: #000;cursor: pointer;" id="room"></div>
							</div>
							<table cellspacing="" cellpadding="">
								<tr>
									<td id="morning"></td>
								</tr>
								<tr>
									<td id="afternoon"></td>
								</tr>
							</table>
						</div>
					</div>
					<div class="weui-flex" style="position: absolute;bottom: 0;width: 100%;">
						<div class="weui-flex__item" id="create">
							<div class="placeholder">
								<a href="javascript:;" class="weui-btn weui-btn_primary" disabled>创建会议</a>
							</div>
						</div>
						<div class="weui-flex__item" id="more" style="display:none">
							<div class="placeholder">
								<a href="javascript:;" class="weui-btn weui-btn_default">更多</a>
							</div>
						</div>
					</div>
				</div>

				<div class="weui-tabbar">
				</div>
			</div>
		</div>
		<div class="page" id="room_build" style="background:  #EFEFF4;display: none;">
			<div class="weui-tab">
				<div class="weui-tab__bd">
					<div style="font-size:12px;color: #ADADAD;height: 30px;line-height: 30px;margin-left: 4%;">会议室信息</div>
					<div class="weui-cells weui-cells_form" style="margin-top: 0px;">
						<div class=weui-cell>
							<div class=weui-cell__hd><label class=weui-label>名称</label></div>
							<div class=weui-cell__bd> <input id="title" class=weui-input type=text required placeholder=输入会议室名称> </div>
							<div class=weui-cell__ft> <i class=weui-icon-warn></i> </div>
						</div>
						<div class=weui-cell>
							<div class=weui-cell__hd><label class=weui-label>备注</label></div>
							<div class=weui-cell__bd> <input id="content" class=weui-input type=text required placeholder=输入位置等信息> </div>
							<div class=weui-cell__ft> <i class=weui-icon-warn></i> </div>
						</div>
					</div>
					<div class="weui-cells__tips">修改该会议室信息</div>
					<div class="weui-btn-area">
						<a class="weui-btn weui-btn_primary" href="javascript:" onclick="roomcreate()">确定</a>
					</div>
				</div>
			</div>
		</div>
		<!--BEGIN dialog2-->
		<div class="js_dialog" id="iosDialog2" style="display:none">
			<div class="weui-mask"></div>
			<div class="weui-dialog">
				<div class="weui-dialog__hd"><strong class="weui-dialog__title">创建成功！</strong></div>
				<!--<div class="weui-dialog__bd">3s后将跳转至我的保修单页面</div>-->
				<div class="weui-dialog__ft">
					<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" onclick="dialogHide()">确定</a>
				</div>
			</div>
		</div>
		<!--END dialog2-->
		<script src="${base}/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/jquery-weui.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/flex.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/iscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/navscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/date.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function parseURL(url) {
				if(url.indexOf("?") == -1) return
				var url = url.split("?")[1];
				var res = [];
				if(url.indexOf("&") == -1) {
					var arr = url.split("=");
					res[arr[0]] = arr[1]
				} else {
					var arr = url.split("&");
					for(var i = 0; i < arr.length; i++) {
						var key = arr[i].split("=");
						res[key[0]] = key[1]
					}
				}
				return res

			}
			var url2 = window.location.href;
			var userid = '<%=userid %>';
			url2 = decodeURIComponent(url2)
			var res = parseURL(url2)
			if(res.flag == "1") {
				$("#more").show()
			}
			$("#room").html(res.room);
			$("#title").val(res.room)
			var mdata = [];
			setTimeout(function() {
				$.ajaxSettings.async = false;
				$.post("${base}/meet/orderByRoom", {
					roomname: res.room
				}, function(data) {
					mdata = data;
					for(var i = 0; i < data.length; i++) {
						var time = data[i].starttime;
						var year = time.slice(0, 10).split("-")[0];
						var month = time.slice(0, 10).split("-")[1];
						if(month[0] == "0") {
							month = month[1]
						}
						var date = time.slice(0, 10).split("-")[2];
						if(date[0] == "0") {
							date = date[1]
						}
						var day = year + "-" + month + "-" + date;
						var html = '<span class="weui-badge weui-badge_dot" style="margin-left: 17px;position: fixed;top: 3px;padding:4px"></span>'
						$('[data-day="' + day + '"]').append(html)
					}
				})
				$.ajaxSettings.async = false;
				var myDate = new Date();
				var date = myDate.getDate();
				program(date)
			}, 100)

			function dialogHide() {
				$("#iosDialog2,.weui-dialog,.weui-mask").hide()
				$("#container").show().siblings().hide()
			}

			function getnum(time) {
				var a = time.slice(0, 10).split("-");
				return a[2]
			}

			function gethour(time) {
				var a = time.slice(11).split(":");
				return a[0]
			}
			$('.clearfix').on('click', 'li', function() {
				$("#afternoon,#morning").html("")
				$("#afternoon,#morning").removeClass("otherusing")
				$("#afternoon,#morning").removeClass("select")
				var date = $(this).children().html()
				program(date)
			})

			$(".right").on("click", "#afternoon,#morning", function() {
				if($(this).html() == "") {
					$(this).toggleClass("select")
				}
			})
			$("#create").click(function() {
				var myDate = new Date();
				var year = $("li.cur").attr("data-year");
				var month = $("li.cur").attr("data-month");
				var date = $("li.cur").children().html()
				if(date < 10) {
					date = "0" + date
				}
				if(month < 10) {
					month = "0" + month
				}
				var starttime, finishtime;
				if($(".select").length > 1) {
					starttime = year + "-" + month + "-" + date + "T09:00";
					finishtime = year + "-" + month + "-" + date + "T18:00";
				} else if($(".select").length == 1) {
					var type = $(".select").attr("id")
					if(type == "morning") {
						starttime = year + "-" + month + "-" + date + "T09:00";
						finishtime = year + "-" + month + "-" + date + "T12:00";
					} else if(type == "afternoon") {
						starttime = year + "-" + month + "-" + date + "T14:00";
						finishtime = year + "-" + month + "-" + date + "T18:00";
					}
				} else {
					$(".weui-dialog__title").html("请选择好时间后，再进行创建")
					$("#iosDialog2,#iosDialog2 .weui-dialog,#iosDialog2 .weui-mask").show()
					return
				}
				var device = res.device;
				var room = $("#room").html()
				var href = "${base}/meet/ordernav?room=" + room + "&type=" + res.flag + "&starttime=" + starttime + "&finishtime=" + finishtime + "&device=" + device;
				location.href = href;
			})
			$("#more").click(function() {
				$.actions({
					actions: [{
						text: "编辑会议室信息",
						className: "color-primary",
						onClick: function() {
							$("#container").hide() //do something
							$("#room_build").show()
						}
					}, {
						text: "删除该会议室",
						className: "color-warning",
						onClick: function() {
							$.confirm({
								title: '删除会议室',
								text: '确定删除？',
								onOK: function() {
									$(".weui-dialog").hide()
									$(".weui-mask").hide()
									$.post("${base}/meet/delete", { //删除会议室信息
										xh: res.xh
									}, function(data) {
										if(data.res == true) {
											$(".weui-dialog__title").html("删除成功！")
											$("#iosDialog2,#iosDialog2 .weui-dialog,#iosDialog2 .weui-mask").show()
											setTimeout(function(){
												location.href = "${base}/meet/meetroomnav?type=pri"
											},2000)
											
										} else {
											$(".weui-dialog__title").html("删除失败！")
											$("#iosDialog2,#iosDialog2 .weui-dialog,#iosDialog2 .weui-mask").show()
										}
									})

									//点击确认
								},
								onCancel: function() {
									$(".weui-dialog").hide()
									$(".weui-mask").hide()
								}
							});
						}
					}]
				});
				$(".weui-mask").hide()
			})

			function roomcreate() { //编辑会议室信息
				var name = $("#title").val();
				var content = $("#content").val();

				$.post("${base}/meet/edit", { //修改会议室信息
					xh: res.xh,
					roomname: name,
					bz: content
				}, function(data) {
					if(data.res == true) {
						$(".weui-dialog__title").html("修改成功！")
						$("#iosDialog2,#iosDialog2 .weui-dialog,#iosDialog2 .weui-mask").show()
						$("#room").html(name)
					} else {
						$(".weui-dialog__title").html("修改失败！")
						$("#iosDialog2,#iosDialog2 .weui-dialog,#iosDialog2 .weui-mask").show()
					}
				})

			}
		</script>

	</body>

</html>